package reader.components;

import java.util.Map;

import reader.xml.XMLContext;
import reader.xml.XMLHelper;

import components.AbstractComponent;
import components.Device;


public class DeviceRW extends AbstractComponentRW {

    private static final String NAME = "name";

    private static final String PASSWORD = "password";

    private static final String HOST = "host";

    private static final String PORT = "port";

    public DeviceRW(Map opened) {
        super(opened);
    }

    @Override
    public void read(AbstractComponent component, XMLContext context) {
        Device device = (Device) component;
        device.setName(XMLHelper.readStringProperty(context, NAME));
        device.setPassword(XMLHelper.readIntProperty(context, PASSWORD));
        device.setHost(XMLHelper.readStringProperty(context, HOST));
        device.setPort(XMLHelper.readIntProperty(context, PORT));
        super.read(component, context);
    }

    @Override
    public void write(AbstractComponent component, XMLContext context) {
        Device device = (Device) component;
        XMLHelper.writeProperty(context, NAME, device.getName());
        XMLHelper.writeProperty(context, PASSWORD, device.getPassword());
        XMLHelper.writeProperty(context, HOST, device.getHost());
        XMLHelper.writeProperty(context, PORT, device.getPort());
        super.write(component, context);
    }

}
